<?php

namespace app\common\model\assistant;

use think\Model;


class Assistant extends Model
{

    const RECOMMEND_STATUS_YES=1;
    const RECOMMEND_STATUS_NO=0;
    CONST IN_SERVICE_STATUS_ON = 1; // 在线
    CONST IN_SERVICE_STATUS_OFF = 0; // 离线

    CONST REVIEW_STATUS_WAIT = 0; // 待审核
    CONST REVIEW_STATUS_PASS = 1; // 审核通过
    CONST REVIEW_STATUS_REJECT = 2; // 审核拒绝

    CONST ORDER_SWITCH_ON = 1; // 待接单
    CONST ORDER_SWITCH_OFF = 0; // 待接单
    CONST STATUS_ENABLE = 0; // 启用
    CONST STATUS_DISABLE = 1; // 禁用
    CONST STATUS_FOREVER_DISABLE = 2; // 永久禁用

    CONST TYPE_PERSONAL = 1; // 个人助教
    CONST TYPE_STORE = 2; // 门店助教

    // 表名
    protected $name = 'assistant';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'type_text',
        'gender_text',
        'status_text',
        'review_status_text',
        'order_switch_text',
        'create_time_text',
        'update_time_text'
    ];
    

    public static function getTypeName($value,$data){
        return $data[$value] ?? '未知';
    }
    public static function getOrderSwitchName($value,$data)
    {
        return $data[$value] ?? '未知';
    }
    
    public function getTypeList()
    {
        return ['1' => '个人', '2' => '门店'];
    }

    public function getGenderList()
    {
        return ['1' => __('Gender 1'), '2' => __('Gender 2')];
    }

    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2')];
    }

    public function getReviewStatusList()
    {
        return ['0' => __('Review_status 0'), '1' => __('Review_status 1'), '2' => __('Review_status 2')];
    }

    public function getOrderSwitchList()
    {
        return ['0' => '关闭', '1' => '开启'];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getGenderTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['gender']) ? $data['gender'] : '');
        $list = $this->getGenderList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getReviewStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['review_status']) ? $data['review_status'] : '');
        $list = $this->getReviewStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getOrderSwitchTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['order_status']) ? $data['order_status'] : '');
        $list = $this->getOrderSwitchList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getCreateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getUpdateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setCreateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setUpdateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
